<% layout("/layouts/micro.html",{title:"报名名单管理"}){ %>
<div class="layui-fluid">
	<div class="layui-card">
		<div class="layui-form layui-card-header layuiadmin-card-header-auto">
			<div class="layui-form-item">
				<div class="layui-inline">
					<label class="layui-form-label">学员姓名：</label>
					<div class="layui-input-block">
						<input class="layui-input" name="name" id="name" autocomplete="off">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">监护人：</label>
					<div class="layui-input-block">
						<input class="layui-input" name="guardianName" id="guardianName" autocomplete="off">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">手机：</label>
					<div class="layui-input-block">
						<input class="layui-input" name="guardianTel" id="guardianTel" autocomplete="off">
					</div>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">课程类型：</label>
					<div class="layui-input-block">
						<select name="courseType">
							<option value="" label="全部"/>
                            <%
                            var courseTypes = @EduUtils.getCourseTypes();
                            for(courseType in courseTypes){
                            %>
                            <option value="${courseType.id}" <%if(enrollList.courseType==courseType.id){%>selected<%}%> >${courseType.name}</option>
                            <%}%>
						</select>
					</div>
				</div>
				<!--<div class="layui-inline">
					<label class="layui-form-label">状态：</label>
					<div class="layui-input-block">
						<#radio name="status" value="${enrollList.status!}" items="${@DictUtils.getDictList('yes_no')}" />
					</div>
				</div>-->
				<div class="layui-inline">
					<button class="layui-btn layuiadmin-btn-useradmin" lay-submit="" lay-filter="LAY-enrollList-search">
						<i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
					</button>
				</div>
			</div>
		</div>
		<div class="layui-card-body">
			<%if(shiro.hasPermission("edu:enrollList:edit")){%>
			<div style="padding-bottom: 10px;">
				<button class="layui-btn layui-btn-normal addenrollList_btn"><i class="layui-icon layui-icon-add-1"></i>添加</button>
				<button class="layui-btn layui-btn-danger delAll_btn"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
			</div>
			<%}%>
			<table id="enrollListList" lay-filter="enrollListList"></table>

			<!--操作-->
			<script type="text/html" id="enrollListListBar">
				<%if(shiro.hasPermission("edu:enrollList:edit")){%>
				<a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
				<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
				<%}%>
				<a class="layui-btn layui-btn-xs layui-btn-primary" lay-event="look">预览</a>
			</script>

            <script type="text/html" id="statusTpl">
                {{#  if(d.status === '1'){ }}
                <span class="layui-badge layui-bg-orange">{{ d.statusLabel }}</span>
                {{#  } else { }}
                <span class="layui-badge layui-bg-green">{{ d.statusLabel }}</span>
                {{#  } }}
            </script>
		</div>
	</div>
</div>

<script>
    layui.use(['form','layer','laydate','table','laytpl'],function(){
        var form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            laydate = layui.laydate,
            laytpl = layui.laytpl,
            table = layui.table;

        //列表
        var tableIns = table.render({
            elem: '#enrollListList',
            url : '${ctx}/edu/enrollList/listAjax',
            cellMinWidth : 95,
            page : true,
            request: {
                pageName: 'pageNo', //页码的参数名称，默认：page
                limitName: 'pageSize' //每页数据量的参数名，默认：limit
            },
            limit : 15,
            limits : [10,15,20,25],
            id : "enrollListListTable",
            cols : [[
                {type: "checkbox", fixed:"left", width:50},
					{field:'name', title: '学员姓名', width:100},
					{field:'sexLabel', title: '性别', width:80},
					{field:'birthday', title: '生日', width:120},
					{field:'guardianTypeLabel', title: '监护人类型', width:100},
					{field:'guardianName', title: '监护人姓名', width:100},
					{field:'guardianTel', title: '监护人手机', width:120},
					{field:'courseTypeLabel', title: '课程类型'},
					{field:'statusLabel', title: '状态',templet:'#statusTpl', width:100},
					{field:'updateDate', title: '更新时间', width:160},
					{title: '操作', width:170, templet:'#enrollListListBar',fixed:"right",align:"center"}
            ]]
        });

        //监听搜索
        form.on('submit(LAY-enrollList-search)', function(data){
            var name = $('#name');
            var sex = $('#sex');
            var guardianName = $('#guardianName');
            var guardianTel = $('#guardianTel');
            var courseType = $('#courseType');
            var status = $('#status');
            //执行重载
            table.reload("enrollListListTable",{
                page: {
                    curr: 1
                },
                where: {
                    name : name.val(),
                    sex : sex.val(),
                    guardianName : guardianName.val(),
                    guardianTel : guardianTel.val(),
                    courseType : courseType.val(),
                    status : status.val(),
                }
            })
        });

        //添加
        function addenrollList(id){
            var index = layui.layer.open({
                title : "添加报名名单",
                type : 2,
                content : "${ctx}/edu/enrollList/form?id="+id,
                maxmin: true,
                area: ['900px', '90%'],
                <%if(shiro.hasPermission("edu:enrollList:edit")){%>
                btn: ['确定', '取消'],
                yes: function(index, layero){
                    var submit = layero.find('iframe').contents().find('#LAY_addData');
                    submit.trigger('click');
                }
				<%}%>
            })
        }
        $(".addenrollList_btn").click(function(){
            var id = '${enrollList.id}';
            addenrollList(id);
        })


        //批量删除
        $(".delAll_btn").click(function(){
            var checkStatus = table.checkStatus('enrollListListTable'),
                data = checkStatus.data,
                selectedIds = [];
            if(data.length > 0) {
                for (var i in data) {
                    selectedIds.push(data[i].id);
                }
                layer.confirm('确定删除选中的数据？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post("${ctx}/edu/enrollList/batchDelete",{selectedIds:selectedIds.join(",")},function(result){
                        if(result.code=="0"){
                            layer.msg(result.msg);
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                })
            }else{
                layer.msg("请选择需要删除的数据");
            }
        })

        //列表操作
        table.on('tool(enrollListList)', function(obj){
            var layEvent = obj.event,
                data = obj.data;

            if(layEvent === 'edit'){ //编辑
                addenrollList(data.id);
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确定删除选中数据？',{icon:3, title:'提示信息'},function(index){
                    $.post("${ctx}/edu/enrollList/delete",{id:data.id},function(result){
                        if(result.code=="0"){
                            layer.msg("删除成功");
                        }else{
                            layer.msg("删除失败");
                        }
                        tableIns.reload();
                        layer.close(index);
                    });
                });
            } else if(layEvent === 'look'){ //预览
                layer.alert("此功能需要前台展示，实际开发中传入对应的必要参数进行文章内容页面访问")
            }
        });

    })
</script>
<%}%>